package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.StreetDeviceClassify;
import com.dwxt.sport.business.service.StreetDeviceClassifyService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 街道 & 设备分类
 *
 * @author Kuang.JiaZhuo
 * @date 2020-08-11 14:59
 */
@RestController
@RequestMapping("/streetDeviceClassify")
@Api(tags={"设备&街道-相关接口"})
public class StreetDeviceClassifyController {

    @Resource
    StreetDeviceClassifyService streetDeviceClassifyService;

    @ApiOperation(value = "新增或修改 街道&设备分类", notes = "新增或修改【街道&设备分类】", response = Integer.class)
    @PostMapping("/back/insertOrUpdateStreetDeviceClassify")
    public BaseResult insertOrUpdateStreetDeviceClassify(
            @ApiParam(value = "ID(新增不传,更新必传)") @RequestParam(required = false) String id,
            @ApiParam(value = "街道id") @RequestParam(required = false) String streetId,
            @ApiParam(value = "名字") @RequestParam(required = false) String name,
            @ApiParam(value = "设备分类(关联数据字典【classification】)")  @RequestParam(required = false)String classification,
            @ApiParam(value = "图片地址") @RequestParam(required = false)String imgUrl
    ){
        StreetDeviceClassify streetDeviceClassify = new StreetDeviceClassify().setId(id)
                .setStreetId(streetId).setClassification(classification).setImgUrl(imgUrl)
                .setName(name);
        int result = this.streetDeviceClassifyService.insertOrUpdateStreetDeviceClassify(streetDeviceClassify);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "按设备分类返回【街道&设备分类】列表", notes = "根据设备分类id获取[街道&设备分类]列表(带分页)", response = StreetDeviceClassify.class)
    @PostMapping("/selectStreetDeviceClassifyByClassification")
    public BaseResult selectStreetDeviceClassifyByClassification(
            @ApiParam(value = "设备分类(关联数据字典【classification】)", required = true) @RequestParam String classification,
            @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        PageInfo<StreetDeviceClassify> pageInfo = this.streetDeviceClassifyService.selectStreetDeviceClassifyByClassification(classification,pageNum,pageSize);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除【街道&设备分类】", notes = "根据ids批量删除【街道&设备分类】", response= Integer.class)
    @PostMapping(value = "/back/deletetStreetDeviceClassifyByIds")
    public BaseResult deletetStreetDeviceClassifyByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.streetDeviceClassifyService.deletetStreetDeviceClassifyByIds(ids);
        return BaseResult.ok(result);
    }
}
